package net.dreamlu.controller.web;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import net.dreamlu.common.Consts;
import net.dreamlu.common.ext.base.BaseController;
import net.dreamlu.common.utils.URLUtils;
import net.dreamlu.model.Blog;

/**
 * 标签列表页
 * Created by L.cm on 2016/8/1.
 */
public class TagsController extends BaseController {
    /**
     * /tags -> 所以标签列表页
     *
     * /tags/nginx -> 相关标签的文章列表
     */
    public void index() {
        String tags = getPara(0);
        // 所有标签页
        if (StrKit.isBlank(tags)) {
            render("tags.jsp");
            return;
        }
        tags = URLUtils.decode(tags);
        int pageNum = getParaToInt(1, 1);
        Page<Blog> page = Blog.dao.pageByTags(pageNum, Consts.BLOG_PAGE_SIZE, tags);
        setAttr("blogPage", page);
        setAttr("postsby", "tags：" + tags);
        setAttr("actionUrl", "/tags/" + tags + "-");
        render("tags.jsp");
    }
}
